package com.central.scheduler.api.utils;

import com.central.scheduler.service.registry.RegistryClient;
import com.central.scheduler.common.enums.NodeType;
import com.central.scheduler.dao.entity.Server;
import com.central.scheduler.dao.entity.ZookeeperRecord;

import java.util.List;
import java.util.Map;

/**
 * @author Tindy
 * @date 2021/12/15
 * @describe
 * monitor zookeeper info todo registry-spi
 * fixme Some of the information obtained in the api belongs to the unique information of zk.
 * I am not sure whether there is a good abstraction method. This is related to whether the specific plug-in is provided.
 */
public class RegistryCenterUtils {

    private static RegistryClient registryClient = RegistryClient.getInstance();

    /**
     * @return zookeeper info list
     */
    public static List<ZookeeperRecord> zookeeperInfoList() {
        return null;
    }

    /**
     * get master servers
     *
     * @return master server information
     */
    public static List<Server> getMasterServers() {
        return registryClient.getServerList(NodeType.MASTER);
    }

    /**
     * master construct is the same with worker, use the master instead
     *
     * @return worker server informations
     */
    public static List<Server> getWorkerServers() {
        return registryClient.getServerList(NodeType.WORKER);
    }

    public static Map<String, String> getServerMaps(NodeType nodeType) {
        return registryClient.getServerMaps(nodeType);
    }

    public static List<String> getServerNodes(NodeType nodeType, boolean hostOnly) {
        return registryClient.getServerNodes(nodeType);
    }

    public static boolean isNodeExisted(String key) {
        return registryClient.isExisted(key);
    }

    public static List<String> getChildrenNodes(final String key) {
        return registryClient.getChildrenKeys(key);
    }

    public static String getNodeData(String key) {
        return registryClient.get(key);
    }
}
